/*
 * @Author: Hasbu
 * @LastEditors  : Hasbug
 * @Description: 重点人基础库mixins
 * @Date: 2020-01-08 10:15:48
 * @LastEditTime : 2020-01-08 10:40:18
 */

import { systemConfigurat } from '@/api'
export default {
  methods: {
    openDelGroup (item) {
      this.currentBase = item
      this.DelGroupid = item.key
      this.visible_del = true
      this.getData.departmentId = Number(item.key)
    },
    closeDelGroup () {
      this.visible_del = false
    },
    delAllPerson () { // 删除该分组和重点人
    // 当前这个分组的值在currentBase
      systemConfigurat.deleteFocusGrouping({ id: Number(this.DelGroupid) }).then(res => {
        this.$message.success('删除该分组成功！')
        this.BatchList()
        this.getMyPersonTree()
        this.selectBase = []
        this.getData.departmentId = 0
        this.closeDelGroup() // 执行关闭
      })
    },
    selectGroup (value) { // 选择移动的分组
      this.groupId = value
    },
    showClick () {
      if (this.selectedRowKeys.length === 0) {
        this.$message.warning('请选择人员')
      } else {
        this.showMove = true
        this.groups = []
        systemConfigurat.getFocusGroupingList().then(res => {
          for (let i = 0; i < res.data.length; i++) {
            this.groups.push({ value: res.data[i].id, title: res.data[i].name })
          }
        })
      }
    },
    movePerson () { // 提交移动到那个分组
      let data = {}
      if (!this.groupId) {
        this.$message.error('未选择分组')
        return false
      }
      data.departmentId = Number(this.groupId)
      data.focalpointId = []
      for (let i = 0; i < this.selectedRows.length; i++) {
        data.focalpointId.push(this.selectedRows[i].id)
      }
      systemConfigurat.moveList(data).then(res => {
        if (res.data.status === 'ok') {
          this.getsysment()
        }
      })
      this.showMove = false
      this.fenzuFlag = false
    },
    personChange (val) {
      let that = this
      // 新增编辑用户之后的回调
      that.visible_user_import = false
      that.visible_user_add = false
      that.visible_user_edit = false
      that.visible_user_remove = false
      if (val === 'success') {
        // 刷新当前分组部门下的用户
        that.getsysment()
      }
    },
    baseChange (val) {
      // 基础库新增或者编辑后的回调
      if (val) {
        // 代表新增基础库成功，需要刷新基础库树。
        this.searchName = ''
        this.selectBase = []
        this.getData.departmentId = 0
        this.BatchList()
      }
      this.visible_base_add = false
      this.visible_base_edit = false
    },
    userAddDatasz () {
      this.userAddData.sectionName = ''
      this.userAddData.sectionId = ''
      this.userAddData.groupName = ''
      this.userAddData.groupId = ''
      this.userAddData.isData = false
    }

  }
}
